<template>
  <div class="chart" ref="myline"></div>
</template>

<script>
import * as echarts from 'echarts'
import resize from '@/mixins/resize'
export default {
  name: 'LineChart',
  mixins: [resize],
  mounted() {
    // 注意必须要给chart给宽高
    // 初始化
    this.myEchart = echarts.init(this.$refs.myline)
    this.myEchart.setOption({
      xAxis: {
        type: 'category',
        show: false,
        // 轴两边的距离
        boundaryGap: false
      },
      yAxis: {
        show: false
      },

      series: {
        type: 'line',
        data: [15, 20, 35, 25, 19, 20, 30, 15],
        // 曲线平滑
        smooth: true,
        // 拐点不显示
        itemStyle: {
          opacity: 0
        },
        // 设置鼠标移上没有hover效果
        silent: true,
        // 区域填充，线性渐变
        areaStyle: {
          color: {
            type: 'linear',
            x: 0,
            y: 0,
            x2: 0,
            y2: 1,
            colorStops: [
              {
                offset: 0,
                color: '#d3bcf4' // 0% 处的颜色
              },
              {
                offset: 1,
                color: '#fff' // 100% 处的颜色
              }
            ],
            global: false // 缺省为 false
          }
        }
      },
      grid: {
        top: 0,
        bottom: 0,
        left: 0,
        right: 0
      }
    })
  }
}
</script>

<style>
.chart {
  width: 100%;
  height: 100%;
}
</style>
